<template>
  <div class="app-container">
    <div class="handle-content">
      <el-input v-if="this.$store.getters.role.store_id == 0" v-model="storeId" placeholder="请输入店铺id" style="width: 200px;margin-right: 10px;" />
      <el-input v-model="phone" placeholder="请输入手机号" style="width: 200px;margin-right: 10px;" />
      <el-input v-model="userId" placeholder="请输入用户ID" style="width: 250px;margin-right: 10px;">
        <el-button slot="append" @click="search">查询</el-button>
      </el-input>
    </div>

    <el-table v-loading="listLoading" :data="list" element-loading-text="拼命加载中" border fit highlight-current-row>
      <el-table-column v-if="this.$store.getters.role.store_id == 0" label="店铺ID" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.store_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center">
        <template slot-scope="scope">
          {{ scope.row.user_id }}
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center">
        <template slot-scope="scope">
          {{ scope.row.phone }}
        </template>
      </el-table-column>
      <el-table-column label="验证码" align="center">
        <template slot-scope="scope">
          {{ scope.row.code }}
        </template>
      </el-table-column>
      <el-table-column label="验证码类型" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.type == 1">注册</span>
          <span v-else-if="scope.row.type == 2">登录</span>
          <span v-else-if="scope.row.type == 3">忘记密码</span>
          <span v-else-if="scope.row.type == 4">重置手机</span>
          <span v-else-if="scope.row.type == 5">设置密码</span>
          <span v-else-if="scope.row.type == 6">转账验证</span>
        </template>
      </el-table-column>
      <el-table-column label="发送时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.created_at }}
        </template>
      </el-table-column>
      <el-table-column label="有效时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.expire_at }}
        </template>
      </el-table-column>
    </el-table>
    <pagination v-if="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { getList } from '@/api/code'
export default {

  components: { Pagination },

  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        page: 1,
        storeId: 0,
        userId: '',
        phone: '',
        pageSize: 10
      },
      total: 0,
      storeId: '',
      phone: '',
      userId: ''
    }
  },

  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },

    search() {
      this.listQuery.storeId = this.storeId
      this.listQuery.userId = this.userId
      this.listQuery.phone = this.phone
      this.getList()
    }

  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container{
    .handle-content{
        margin-bottom: 20px;
        .right{
            float: right;
        }
    }
}
</style>
<style>
.el-table .warning-row {
}

.el-table .success-row {
}
</style>
